package entity.model.relationships;

import entity.model.Entity;

import java.lang.reflect.Field;

import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;

public class OneToOne extends Relationship<entity.model.annotations.OneToOne> {
    public OneToOne(Entity owner, Entity possession, Field field) {
        super(owner, possession, field, entity.model.annotations.OneToOne.class);
    }

    @Override
    protected String createPossessionPropertyName() {
        if (annotation != null && annotation.hasOne().length() > 0)
            return  annotation.hasOne();

        return possession.getTitle().toLowerCamel();
    }

    @Override
    protected String createOwnerPropertyName() {
        if (annotation != null && annotation.belongsTo().length() > 0)
            return annotation.belongsTo();

        return UPPER_CAMEL.to(LOWER_CAMEL, field.getName());
    }

    public boolean isReversed() {
        return annotation.reversed();
    }
}
